/*
 *
 * This file is part of Aion SLX Emu.
 *
 * This is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser Public License
 * along with this software.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Homepage : http://team-lx.net
 * Support Client Version : Aion 2.7 - (NA) 
 * Aion Emulator Version : Aion SLX 2.7
 */

package gameserver.services;

import gameserver.model.gameobjects.Monster;
import gameserver.model.gameobjects.player.Player;
import gameserver.model.group.PlayerGroup;
import gameserver.model.templates.spawn.SpawnTemplate;
import gameserver.utils.PacketSendUtility;
import gameserver.spawn.SpawnEngine;

public class KysisInstanceService
{
	public void onGroupReward(Monster monster, PlayerGroup group)
	{
		// When kills Ranx Esfor spawn Ranx Medico
        if(monster.getObjectTemplate().getTemplateId() == 215171)
        {
            SpawnTemplate esfo;
		
            esfo = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 215172, 526.70703f, 632.3256f, 180.27338f, (byte)91, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(esfo, group.getGroupLeader().getInstanceId());
		}
	
		// When kills Ranx Medico spawn Ebonlord Nukuam
        if(monster.getObjectTemplate().getTemplateId() == 215172)
        {
            SpawnTemplate nukuam;
		
            nukuam = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 215177, 527.4959f, 727.0254f, 192.60934f, (byte)90, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(nukuam, group.getGroupLeader().getInstanceId());
		}	
		
		// When kills Ebonlord Nukuam spawn Boss Awakened Kysis Duke
        if(monster.getObjectTemplate().getTemplateId() == 215177)
        {
            SpawnTemplate duke;
		
            duke = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 215179, 526.45624f, 845.3402f, 199.45187f, (byte)90, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(duke, group.getGroupLeader().getInstanceId());
		}	
	
        //Countdown to kill the Boss Awakened Kysis Duke and chests appear
		if(monster.getObjectTemplate().getTemplateId() == 215179)
		{
		    long timeRemain = (group.getInstanceStartTime() + 900000) - System.currentTimeMillis();
            
            if(timeRemain > 1)
			{
			//When kills Awakened Kysis Duke spawns chests
            SpawnTemplate chest1, chest2, chest3, chest4, chest5, chest6, chest7, chest8, chest9, chest10, chest11;
            
            chest1 = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 214804, 478f, 815f, 199f, (byte)10, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(chest1, group.getGroupLeader().getInstanceId());

            chest2 = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 214804, 471f, 834f, 199f, (byte)3, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(chest2, group.getGroupLeader().getInstanceId());

            chest3 = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 214804, 471f, 854f, 199f, (byte)117, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(chest3, group.getGroupLeader().getInstanceId());

            chest4 = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 214804, 478f, 873f, 199f, (byte)110, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(chest4, group.getGroupLeader().getInstanceId());

            chest5 = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 214804, 490f, 888f, 199f, (byte)103, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(chest5, group.getGroupLeader().getInstanceId());

            chest6 = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 214804, 508f, 899f, 199f, (byte)96, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(chest6, group.getGroupLeader().getInstanceId());

            chest7 = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 214804, 527f, 902f, 199f, (byte)90, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(chest7, group.getGroupLeader().getInstanceId());

            chest8 = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 214804, 547f, 899f, 199f, (byte)84, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(chest8, group.getGroupLeader().getInstanceId());

            chest9 = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 214804, 564f, 889f, 199f, (byte)77, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(chest9, group.getGroupLeader().getInstanceId());

            chest10 = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 214804, 577f, 874f, 199f, (byte)70, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(chest10, group.getGroupLeader().getInstanceId());

            chest11 = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 214804, 584f, 855f, 199f, (byte)63, 0, 0, true);
            SpawnEngine.getInstance().spawnObject(chest11, group.getGroupLeader().getInstanceId());
            }
            else {
                for(Player member : group.getMembers())
                {
                    //TODO: Find retail message
                    PacketSendUtility.sendMessage(member, "Your group is very slow. No chests reward for instance.");
                }
            }
		}

        //When kills 11 Sealed Gold Chest spawn Ancient Treasure Box
        if(monster.getObjectTemplate().getTemplateId() == 214804) {
            
            group.setInstanceKills(group.getInstanceKills() + 1);
            
            if (group.getInstanceKills() == 11){
                SpawnTemplate goldchest;
				
                goldchest = SpawnEngine.getInstance().addNewSpawn(300120000, group.getGroupLeader().getInstanceId(), 700560, 585f, 835f, 199f, (byte)57, 0, 0, true);
                SpawnEngine.getInstance().spawnObject(goldchest, group.getGroupLeader().getInstanceId());
            }
        }
	}
	
	public static KysisInstanceService getInstance()
	{
		return SingletonHolder.instance;
	}
	
	@SuppressWarnings("synthetic-access")
	private static class SingletonHolder
	{
		protected static final KysisInstanceService	instance	= new KysisInstanceService();
	}
}